"""
使用asyncio实现异步IO

asyncio的编程模型就是一个消息循环。
"""

import threading
import asyncio


@asyncio.coroutine
def say_hello():
    print("hello python! {name}".format(name=threading.current_thread().name))
    yield from asyncio.sleep(3)
    print("hello again! {name}".format(name=threading.current_thread().name))


def run():
    # 获取消息循环
    loop = asyncio.get_event_loop()
    tasks = [say_hello(), say_hello()]
    loop.run_until_complete(asyncio.wait(tasks))
    loop.close()


if __name__ == "__main__":
    run()
